package BanyuanClub.Study.Day0309.线程池;

import java.util.concurrent.*;

public class TextThreadPool {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //缓存线程池 重复使用旧的线程
        ExecutorService pool = Executors.newCachedThreadPool();
        //固定数量线程池
        ExecutorService pool1 = Executors.newFixedThreadPool(5);
        //单例线程池
        ExecutorService pool2 = Executors.newSingleThreadExecutor();
        //具有延迟性的线程池
        ExecutorService pool3 = Executors.newScheduledThreadPool(5);

        /**
         * coreSize 核心线程数
         * maximumPoolSize 最大线程数(核心线程+非核心)
         * keepAliveTime 空闲线程(非核)存活时间
         * unit 时间单位
         * workQueue 任务队列 ArrayBolockingQueue(5)
         */
        new ThreadPoolExecutor(1000,110, 10,
                TimeUnit.SECONDS,new ArrayBlockingQueue<>(500));

        //执行Runnable
        pool.execute(() -> {
            //之前run()里的代码
        });

        //执行Callable
        Future<Integer> fu = pool.submit(() -> {
            //之前call()里的代码
            return 100;
        });
        int n = fu.get();
    }
}
